home *** CD-ROM | disk | FTP | other *** search
/ SGI Hot Mix 17 / Hot Mix 17.iso / HM17_SGI / research / bin / yesno < prev   
Encoding:
Text File  |  1997-07-08  |  696 b   |  38 lines

  1. #!/bin/sh
  2. #
  3. #    $Id: yesno,v 1.3 1996/11/23 05:30:21 ali Exp $
  4. #
  5. # This script asks a y/n question of the user:
  6. #
  7. #    $* - The y/n question to ask, without the "(y/n) ?" at the end.
  8. #
  9. # A 0 is echoed for "no", a 1 for "yes".
  10. #
  11.  
  12. if [ "`echo -n testing123`" = "testing123" ]; then
  13.   ECHO_NONL="echo -n"
  14.   ECHO_NONL_TAIL=
  15. else
  16.   ECHO_NONL=echo
  17.   ECHO_NONL_TAIL=\\c
  18. fi
  19.  
  20.  
  21. RESP=""
  22. while [ "$RESP" != y -a "$RESP" != n ]
  23. do
  24.   $ECHO_NONL "$*? (y/n): $ECHO_NONL_TAIL" > /dev/tty
  25.   read RESP
  26.   RESP=`echo $RESP | tr [A-Z] [a-z]`
  27.   if [ "$RESP" != y -a "$RESP" != n ]; then
  28.     echo "        <Please answer y for yes or n for no>" > /dev/tty
  29.   fi
  30. done
  31. if [ "$RESP" = y ]; then
  32.   echo 1
  33. else
  34.   echo 0
  35. fi
  36.  
  37. exit 0
  38.